home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Fixation 1.3
/
window.c
< prev
next >
Wrap
Text File
|
1996-04-11
|
35KB
|
1,315 lines
/*****
* myWindow.c
*
*
*****/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "mytypes.h"
#include "error.h"
#include "fastmap.h"
#include "graphics.h"
#include "window.h"
#include "main.h"
#include "ResRefs.h"
#include "util.h"
#include "preffile.h"
#include "outgoing.h"
#include "globals.h"
#include "game.h"
#include "tcpstuff.h"
enum {
kTypeHeight = 16
};
typedef struct {
short itemType;
Handle item;
Rect box;
} iteminfo;
#define kNumHistories 8
#define kHistoryLength 256
char history[kNumHistories][kHistoryLength];
short curhis = 0;
WindowPtr myWindow; // addressWindow;
TEHandle myText, typeText;
ControlHandle gVBar;
short gGameWindDepth;
Rect dragRect;
Rect windowBounds = {50, 16, 340, 520};
//Rect gameWindowBounds = {40, 4, 40 + 300, 4 + kWinSize};
//Rect statusWindowBounds = {40, 16 + kWinSize, 140, 640 - 16};
Rect screenRect;
int useColor = false;
short gLinesInText;
// it's an old way to do it, and though Apple doesn't promise to support it,
// I bet they will
static void CheckForColor()
{
SysEnvRec se;
if (SysEnvirons(1, &se) == 0)
if (se.hasColorQD)
useColor = true;
}
short
GetLineHeight(TEHandle tt)
{
TextStyle tstyle;
short lineHeight, dd;
TEGetStyle(0, &tstyle, &lineHeight, &dd, tt);
return lineHeight;
}
// yes, very functional . . .
void
CalcVisLines(void)
{
short height = (**myText).viewRect.bottom - (**myText).viewRect.top;
// gLinesInText = height / (**myText).lineHeight;
gLinesInText = height / GetLineHeight(myText);
}
void CalcVBar(void)
{
short old, ctlMax;
ctlMax = (**myText).nLines - gLinesInText;
if (ctlMax < 0)
ctlMax = 0;
old = GetCtlMax(gVBar);
if (old != ctlMax) {
short val = GetCtlValue(gVBar);
if (val == old) {
// they were at bottom we should scroll this joint
(**gVBar).contrlValue = ctlMax; // illegal but twice as fast,
// as not drawn twice
SetCtlMax(gVBar, ctlMax);
Adjust_text();
}
else {
// they were elsewhere
SetCtlMax(gVBar, ctlMax);
}
// DrawControls(myWindow);
}
}
/*
static void
LoadAddressDialog(void)
{
addressWindow = (WindowPtr) GetNewDialog(rAddressDialog, 0, (WindowPtr) -1L);
verify(addressWindow);
}
*/
void SetUpWindow(void)
{
short i, type;
Rect box;
dragRect = qd.screenBits.bounds;
CheckForColor();
maindev = GetMainDevice();
// set up text window
myWindow = (WindowPtr) NewCWindow(0L, &windowBounds, "\pFixation", false, documentProc, (WindowPtr) -1L, false, 0);
verify(myWindow);
// remember location of window from last time
if (!EmptyRect(&gPrefs.textWindPos)) {
MoveWindow(myWindow, gPrefs.textWindPos.left, gPrefs.textWindPos.top, false);
SizeWindow(myWindow, gPrefs.textWindPos.right - gPrefs.textWindPos.left,
gPrefs.textWindPos.bottom - gPrefs.textWindPos.top, false);
}
ShowWindow(myWindow);
SetPort(myWindow);
TextFont(gPrefs.currentFont);
TextSize(gPrefs.currentSize);
box = myWindow->portRect;
InsetRect(&box, 4, 6);
box.right -= 16; // for scroll bar
box.bottom -= kTypeHeight + 2; // for other field
// make text field where one reads text
myText = TEStylNew(&box, &box);
// myText = TENew(&box, &box);
TEActivate(myText);
TEAutoView(false, myText);
CalcVisLines();
// make text field where one types
TextFont(monaco);
TextSize(9);
box = myWindow->portRect;
box.top = box.bottom - kTypeHeight + 1;
InsetRect(&box, 4, 2);
box.right -= 16;
typeText = TENew(&box, &box);
TEActivate(typeText);
TEAutoView(true, typeText);
box = myWindow->portRect;
SetRect(&box, box.right - 15, box.top - 1, box.right + 1, box.bottom + 2 - 16);
gVBar = NewControl(myWindow, &box, "\p", true, 0, 0, 0, 16, 0);
TEFromScrap();
// SelectWindow((WindowPtr) gameWindow);
for (short nnn=0;nnn<kNumHistories;nnn++)
history[nnn][0] = 0;
if ((**(*maindev)->gdPMap).pixelSize != 8)
tprintf("Fixation works more slowly when not in 256 colors.\r");
}
void
DrawTextWindow(void)
{
EraseRect(&myWindow->portRect);
TEUpdate(&myWindow->portRect, myText);
TEUpdate(&myWindow->portRect, typeText);
DrawControls(myWindow);
// MoveTo(0, myWindow->portRect.bottom - kTypeHeight);
// Line(myWindow->portRect.right - 16, 0);
DrawGrowIcon(myWindow);
}
// the foolish user thinks the window is the wrong size
void
GrowTextWindow(Point pt)
{
Rect sr = { 80, 80, 1024, 1024 };
short oldh, oldv, dh, dv, newh, newv;
SetPort(myWindow);
// remember current size
oldh = myWindow->portRect.right; oldv = myWindow->portRect.bottom;
// do the green thumb shit
long ret = GrowWindow(myWindow, pt, &sr);
SizeWindow(myWindow, LoWord(ret), HiWord(ret), false);
newh = myWindow->portRect.right; newv = myWindow->portRect.bottom;
dh = newh - oldh; dv = newv - oldv;
InvalRect(&myWindow->portRect);
// adjust main text field
(**myText).destRect.right += dh; (**myText).destRect.bottom += dv;
(**myText).viewRect.right += dh; (**myText).viewRect.bottom += dv;
TECalText(myText);
CalcVisLines();
// adjust text field where one types
Rect box = myWindow->portRect;
box.top = box.bottom - kTypeHeight + 1;
InsetRect(&box, 4, 2);
box.right -= 16;
(**typeText).destRect = box;
(**typeText).viewRect = box;
TECalText(typeText);
SizeControl(gVBar, 16, newv - 13);
MoveControl(gVBar, newh - 15, -1);
CalcVBar();
}
#define ran(x) (abs(Random()) % (x))
#define flip (ran(2) == 0)
static void
CoolPerson(char *s)
{
if (flip)
switch(ran(4)) {
case 0: strcat(s, "phat "); break;
case 1: strcat(s, "straight "); break;
case 2: strcat(s, "funky "); break;
case 3: strcat(s, "mad "); break;
}
switch(ran(8)) {
case 0: strcat(s, "gangsta"); break;
case 1: strcat(s, "g"); break;
case 2: strcat(s, "home boy"); break;
case 3: strcat(s, "macker"); break;
case 4: strcat(s, "MC"); break;
case 5: strcat(s, "OG"); break;
case 6: strcat(s, "o-dog"); break;
case 7: strcat(s, "gangbanger"); break;
}
}
static void
Location(char *s)
{
switch(ran(8)) {
case 0: strcat(s, "crib"); break;
case 1: strcat(s, "crypt"); break;
case 2: strcat(s, "hood"); break;
case 3: strcat(s, "gray goose"); break;
case 4: strcat(s, "morgue"); break;
case 5: strcat(s, "cell"); break;
case 6: strcat(s, "street"); break;
case 7: strcat(s, "LBC"); break;
}
}
static void
Activity(char *s)
{
switch(ran(16)) {
case 0: strcat(s, "shootin' hoops"); break;
case 1: strcat(s, "mackin'"); break;
case 2: strcat(s, "knocking wood"); break;
case 3: case 12: strcat(s, "smoking ");
switch(ran(7)) {
case 0: strcat(s, "Indo"); break;
case 1: strcat(s, "blunts"); break;
case 2: strcat(s, "crack"); break;
case 3: strcat(s, "chronic"); break;
case 4: strcat(s, "bubonic chronic"); break;
case 5: strcat(s, "joints"); break;
case 6: strcat(s, "hash"); break;
}
break;
case 4:
switch(ran(3)) {
case 0: strcat(s, "sippin' "); break;
case 1: strcat(s, "drinkin' "); break;
case 2: strcat(s, "pounding "); break;
}
switch(ran(4)) {
case 0: strcat(s, "40's"); break;
case 1: strcat(s, "64's"); break;
case 2: strcat(s, "King Cobra"); break;
case 3: strcat(s, "Colt 45"); break;
}
break;
case 5: strcat(s, "bustin' moves"); break;
case 6: strcat(s, "trippin'"); break;
case 7: strcat(s, "takin' no shorts"); break;
case 8: strcat(s, "rolling with da crew"); break;
case 9: strcat(s, "chillin' in the crib"); break;
case 10: strcat(s, "cruising Crenshaw"); break;
case 11: strcat(s, "makin' deals"); break;
case 13: strcat(s, "rollin' in the el dog rag"); break;
case 14: case 15:
strcat(s, "packin' "); break;
switch(ran(4)) {
case 0: strcat(s, "a gat "); break;
case 1: strcat(s, "a nine "); break;
case 2: strcat(s, "a glock "); break;
case 3: strcat(s, "a duece duece "); break;
}
break;
}
}
static short
GreetingString(char *s)
{
short len = strlen(s);
if (len < strlen("poopy x"))
return len;
strncpy(s, "xtell", 5);
s[len++] = 0; s[len] = 0;
if (!isdigit(s[6])) {
strcat(&s[len], &s[6]);
s[len-1] = ' ';
}
else
s[0] = ' ';
if (flip)
strcat(s, "dog");
strcat(s, " is in da house! ");
switch(ran(3)) {
case 0:
flip ? strcat(s, "Kickin' ") : strcat(s, "Kickin' ");
switch(ran(5)) {
case 0: strcat(s, "it "); break;
case 1: strcat(s, "the gangsta funk "); break;
case 2: strcat(s, "g's "); break;
case 3: strcat(s, "the industry "); break;
case 4: strcat(s, "da sixty-fo squares "); break;
}
strcat(s, "for the ");
switch(ran(5)) {
case 0: strcat(s, "nine point deuce "); break;
case 1: strcat(s, "next millenium "); break;
case 2: strcat(s, "hood rats "); break;
case 3: strcat(s, "crack babies "); break;
case 4: strcat(s, "phat crew "); break;
}
switch(ran(3)) {
case 0: strcat(s, "to the max"); break;
case 1: strcat(s, "you know what I'm sayin'"); break;
case 2: strcat(s, "straight up"); break;
}
switch(ran(4)) {
case 0: strcat(s, "! "); break;
case 1: strcat(s, ", g! "); break;
case 2: strcat(s, ", homie! "); break;
case 3: strcat(s, ", homes! "); break;
}
break;
case 1:
switch(ran(3)) {
case 0: strcat(s, "Tearin' up "); break;
case 1: strcat(s, "Rippin' up "); break;
case 2: strcat(s, "Busting up "); break;
}
switch(ran(6)) {
case 0: strcat(s, "g's, "); break;
case 1: strcat(s, "the crib, "); break;
case 2: strcat(s, "da pad, "); break;
case 3: strcat(s, "the house, "); break;
case 4: strcat(s, "other rappers, "); break;
case 5: strcat(s, "da industry, "); break;
}
Activity(s);
if (flip && flip) { // gafflin' props
strcat(s, ", ");
Activity(s);
}
strcat(s, "! ");
break;
case 2:
flip ? strcat(s, "He's da ") : strcat(s, "He's the ");
CoolPerson(s);
flip ? strcat(s, ", back from the ") : strcat(s, ", down from the ");
Location(s);
if (flip) {
strcat(s, ", ");
Activity(s);
}
strcat(s, "! ");
break;
}
/*
nine double-m
ak
drop
tip
tokin' up
one in the chamber
peeled the cap
hocus pocus
12 guage mossbird
yo money
impala
macdaddy
*/
switch (ran(13)) {
case 0: strcat(s, "Better step aside! "); break;
case 1: strcat(s, "No shorts! "); break;
case 2: strcat(s, "Wake your punk booty up! "); break;
case 3: strcat(s, "He gonna gaffle you! "); break;
case 4: strcat(s, "Gettin' mad props! "); break;
case 5: strcat(s, "Hittin' switches! "); break;
case 6: strcat(s, "Get the fou' one one! "); break;
case 7: strcat(s, "Time ta dial nine one one! "); break;
case 8: strcat(s, "He don't fall for the okey-doke! "); break;
case 9: strcat(s, "He'z all that and a pile of grits! "); break;
case 10: strcat(s, "You betta recognize! "); break;
case 11: strcat(s, "The leader of the number one crew in the area! "); break;
case 12: strcat(s, "Straight gangsta mack! "); break;
}
char *temp = &s[strlen(s)];
switch (ran(2)) {
case 0:
if (flip)
strcat(s, "mackin', ");
if (flip) {
if (flip) {
if (flip) strcat(s, "phat ");
strcat(s, "bowl ");
}
strcat(s, "packin', ");
}
if (flip) {
if (flip) strcat(s, "straight ");
else if (flip) strcat(s, "car ");
strcat(s, "jackin', ");
}
if (flip)
strcat(s, "hacking, ");
if (flip)
strcat(s, "wack MC's smackin', ");
if (flip)
strcat(s, "f-seven sacking, ");
if (flip) {
Activity(s);
strcat(s, ", ");
}
switch(ran(4)) {
case 0: strcat(s, "never lackin'! "); break;
case 1: strcat(s, "no need to be askin'! "); break;
case 2: strcat(s, "straight up straight down maxin'! "); break;
case 3: strcat(s, "big deal backin'! "); break;
}
break;
case 1:
switch(ran(7)) {
case 0: strcat(s, "They gonna "); break;
case 1: strcat(s, "He makes other crews "); break;
case 2: strcat(s, "Other crews just "); break;
case 3: strcat(s, "Hood rats "); break;
case 4: strcat(s, "Shorts takin' rappers "); break;
case 5: strcat(s, "Grandmasterz gotta "); break;
case 6: strcat(s, "Wack MC's "); break;
}
switch(ran(6)) {
case 0: strcat(s, "stand aside "); break;
case 1: strcat(s, "step back "); break;
case 2: strcat(s, "back off "); break;
case 3: strcat(s, "shrivel up "); break;
case 4: strcat(s, "disappear "); break;
case 5: strcat(s, "pay respect "); break;
}
switch(ran(5)) {
case 0: strcat(s, "wanna die, "); break;
case 1: strcat(s, "hear their sighs, "); break;
case 2: strcat(s, "make their goodbyes, "); break;
case 3: strcat(s, "ask if ya want fries, "); break;
case 4: strcat(s, "no surprise, "); break;
}
if (flip)
switch(ran(5)) {
case 0: strcat(s, "wanna know why?, "); break;
case 1: strcat(s, "know why?, "); break;
case 2: strcat(s, "makes me cry, "); break;
case 3: strcat(s, "phat 'n sly, "); break;
case 4: strcat(s, "growin' banzais, "); break;
}
switch(ran(5)) {
case 0: strcat(s, "he steps up no trippin' ");
if (flip) strcat(s, "no slippin' ");
break;
case 1: strcat(s, "he pops a cap "); break;
case 2: strcat(s, "he packs his gat "); break;
case 3: strcat(s, "he shows his face "); break;
case 4: strcat(s, "lays a trap "); break;
}
switch(ran(5)) {
case 0: strcat(s, "and they sizzel before your eyes! "); break;
case 1: strcat(s, "and busts their lies! "); break;
case 2: strcat(s, "and smacks the spies! "); break;
case 3: strcat(s, "and hears their cries! "); break;
case 4: strcat(s, "and flies! "); break;
}
break;
}
*temp = toupper(*temp);
len = strlen(s);
return len;
}
// called when the luser hits return in the type field
void
EnteredText(void)
{
long nnn, len;
Handle hand = (**typeText).hText;
len = (**typeText).teLength;
// if (len == 0)
// return; // they opened their mouth, but no words came out . . .
if (len > kGScratchSize - 1) len = kGScratchSize - 1;
// copy text in
for (nnn=0;nnn<len;nnn++)
gScratch[nnn] = ((unsigned char *) (*hand))[nnn];
// history stuff
if (len > 0) {
strncpy(history[0], (char *) gScratch, kHistoryLength-1);
history[0][kHistoryLength-1] = 0;
if (len < kHistoryLength)
history[0][len] = 0;
// copy 'em downwards
for (nnn=kNumHistories-1;nnn>0;nnn--)
strcpy(history[nnn], history[nnn-1]);
}
curhis = 0;
// a little easter egg
gScratch[len] = 0;
if (!strncmp((char *) gScratch, "poopy ", strlen("poopy ")))
len = GreetingString((char *) gScratch);
gScratch[len++] = '\n';
gScratch[len++] = 0;
// see if we should send this to our server
if (nexStatus[0] == kStatOpen) {
bprintf("%s", (char *) gScratch);
}
// now we erase text
TESetText((Ptr) gScratch, 0, typeText);
SetPort(myWindow);
EraseRect(&(**typeText).viewRect);
// output what we typed into myText field
gScratch[len-2] = '\r';
tprintf("%s", (char *) gScratch);
// a little easter egg
if (!strncmp((char *) gScratch, "match adum", strlen("match adum")))
tprintf("It would be a match made in heaven . . . \r");
}
void
HandleKey(char c)
{
long nnn, len;
Handle hand = (**typeText).hText;
if (c >= 0x80 || c < 0)
return; // these keys mess FICS up with Timeseal active
// tprintf("%d ", c);
len = (**typeText).teLength;
if (len > kHistoryLength - 1) len = kHistoryLength - 1;
if (c == 27) {
DoEscapeKey();
}
else if (c == 30) { // up arrow
if (curhis == kNumHistories - 1)
return;
if (history[curhis+1][0] == 0)
return; // don't go back that far
if (curhis == 0) {
// copy text in
for (nnn=0;nnn<len;nnn++)
history[0][nnn] = ((unsigned char *) (*hand))[nnn];
history[0][nnn] = 0;
}
curhis++;
TESetText((Ptr) history[curhis], strlen(history[curhis]), typeText);
SetPort(myWindow);
InvalRect(&(**typeText).viewRect);
}
else if (c == 31) { // down arrow
if (curhis == 0)
return;
curhis--;
TESetText((Ptr) history[curhis], strlen(history[curhis]), typeText);
SetPort(myWindow);
InvalRect(&(**typeText).viewRect);
}
else
TEKey(c, typeText);
}
static void QuickMouseDown (EventRecord *theEvent)
{
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode)
{
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inDrag:
DragWindow(theWindow, theEvent->where, &dragRect);
break;
}
}
Boolean
GetAnAddress(char *name, char *password, char *address, long *port)
{
// items in dialog
enum {
pOkay = 1,
pCancel,
pName,
pPassword,
pIP,
pPort,
pShortcut,
pNotImportant1,
pNotImportant2,
pNotImportant3,
pNotImportant4,
pOpenButt,
pAddButt,
pRemoveButt,
pNotImportant5,
pNotImportant6,
pFics,
pIcc,
pTimeseal,
kFutzer,
kNumItems = kFutzer - 1
};
Boolean okayed = false;
Str255 s;
iteminfo ilist[kNumItems+1];
short i, hitItem = -1;
WindowPtr saveport;
long reg, rep;
DialogPtr dialog;
DialogPeek dpeek;
OSErr err;
Rect box = {1000, 1000, 1010, 1010};
TEHandle fake = TENew(&box, &box);
verify(fake);
dialog = GetNewDialog(rAddressDialog, nil, (WindowPtr) -1L);
verify(dialog);
dpeek = (DialogPeek) dialog;
// err = SetDialogDefaultItem(dialog, pOkay);
// err = SetDialogCancelItem(dialog, pCancel);
ShowWindow(dialog);
SetPort(dialog);
for (i=1;i<=kNumItems;i++) {
ilist[i].item = 0;
GetDItem(dialog, i, &ilist[i].itemType, &ilist[i].item, &ilist[i].box);
verify(ilist[i].item);
}
NumToString(*port, s); SetIText(ilist[pPort].item, s);
// now set the text for the IP field
for (i=0;address[i];i++)
s[i+1] = address[i];
s[0] = i;
SetIText(ilist[pIP].item, s);
// now set the text for the name field
for (i=0;name[i];i++)
s[i+1] = name[i];
s[0] = i;
SetIText(ilist[pName].item, s);
// now set the text for the password field
TESetText(password, strlen(password), fake);
for (i=0;password[i];i++)
s[i+1] = '•';
s[0] = i;
SetIText(ilist[pPassword].item, s);
// SetCtlValue((ControlHandle) ilist[pFics].item, 1);
// HiliteControl((ControlHandle) ilist[pTimeseal].item, 255);
SetCtlValue((ControlHandle) ilist[pFics].item, gPrefs.serverType == kFics);
SetCtlValue((ControlHandle) ilist[pIcc].item, gPrefs.serverType == kIcc);
SetCtlValue((ControlHandle) ilist[pTimeseal].item, gPrefs.timeseal);
// VDebugStr("%d", gPrefs.timeseal);
// set up list of shortcuts
Rect dataBounds = {0, 0, 0, 1}, slistRect;
Point cSize = {0, 0};
Cell cell;
ListHandle slist;
SetRect(&slistRect, ilist[pOpenButt].box.left, ilist[pOpenButt].box.bottom + 8,
ilist[pRemoveButt].box.right - 16, ilist[pOkay].box.bottom);
slist = LNew(&slistRect, &dataBounds, cSize, 0,
(WindowPtr) dialog, true, false, false, true);
verify(slist);
// add cells
short loop;
cell.h = 0;
// add 'em all at once
for (loop=0;loop<kShortcuts;loop++)
if (!gShortcuts[loop].jexiste)
if (loop > 0) {
LAddRow(loop, 32000, slist);
break;
}
for (loop=0;loop<kShortcuts;loop++)
if (gShortcuts[loop].jexiste) {
cell.v = loop;
LSetCell((Ptr) gShortcuts[loop].shortcut, strlen(gShortcuts[loop].shortcut), cell, slist);
}
int ok;
EventRecord theEvent;
DialogPtr dp;
char c;
do {
// ModalDialog(nil, &hitItem);
ok = GetNextEvent (everyEvent, &theEvent);
if (theEvent.what == keyDown || theEvent.what == autoKey)
c = (theEvent.message & charCodeMask);
// do own event handling
WindowPtr theWindow;
switch (theEvent.what) {
case mouseDown:
Point pt = theEvent.where;
SetPort(dialog);
GlobalToLocal(&pt);
if (LClick(pt, 0, slist)) {
Cell cell = LLastClick(slist);
if (cell.v < 0)
break;
// take the shortcut from our memory
Shortcut *sc = &gShortcuts[cell.v];
verify(sc->jexiste);
strcpy((char *) &s[1], sc->shortcut); s[0] = strlen(sc->shortcut);
SetIText(ilist[pShortcut].item, s);
NumToString(gShortcuts[cell.v].port, s);
SetIText(ilist[pPort].item, s);
strcpy((char *) &s[1], sc->name); s[0] = strlen(sc->name);
SetIText(ilist[pName].item, s);
strcpy((char *) &s[1], sc->serverAddress); s[0] = strlen(sc->serverAddress);
SetIText(ilist[pIP].item, s);
TESetText(sc->password, strlen(sc->password), fake);
for (i=0;sc->password[i];i++)
s[i+1] = '•';
s[0] = i;
// strcpy((char *) &s[1], sc->password); s[0] = strlen(sc->password);
SetIText(ilist[pPassword].item, s);
gPrefs.serverType = sc->serverType;
gPrefs.timeseal = sc->timeseal;
SetCtlValue((ControlHandle) ilist[pFics].item, sc->serverType == kFics);
SetCtlValue((ControlHandle) ilist[pIcc].item, sc->serverType == kIcc);
SetCtlValue((ControlHandle) ilist[pTimeseal].item, sc->timeseal);
}
QuickMouseDown(&theEvent);
break;
case updateEvt:
theWindow = (WindowPtr) theEvent.message;
if (theWindow == dialog) {
SetPort(theWindow);
Rect r = slistRect;
InsetRect(&r, -1, -1);
FrameRect(&r);
LUpdate(theWindow->visRgn, slist);
}
break;
case keyDown: case autoKey:
if (((theEvent.modifiers & cmdKey) == 0) && dpeek->editField == pPassword - 1)
if (c != '\t' && c != '\r' && c != '\n') {
(**fake).selStart = (**(dpeek->textH)).selStart;
(**fake).selEnd = (**(dpeek->textH)).selEnd;
TEKey(c, fake);
// hide password
if (c != '\b' && c != 28 && c != 29 && c != 30 && c != 31) {
theEvent.message -= theEvent.message & charCodeMask;
theEvent.message += '•';
}
}
break;
default:
break;
}
if (theEvent.what == keyDown && ((theEvent.modifiers & cmdKey) != 0)
&& c == '.')
hitItem = pCancel;
else if (theEvent.what == keyDown && c == '\r')
hitItem = pOkay;
else if (IsDialogEvent(&theEvent))
if (DialogSelect(&theEvent, &dp, &hitItem)) {
switch (hitItem) {
case pOkay: // check values, make sure they're okay
GetIText(ilist[pName].item, s);
if (s[0] == 0) { hitItem = -1; break; }
GetIText(ilist[pIP].item, s);
if (s[0] == 0) { hitItem = -1; break; }
GetIText(ilist[pPort].item, s);
if (s[0] == 0) { hitItem = -1; break; }
break;
case pAddButt: {
Cell cell = {0, 0};
GetIText(ilist[pShortcut].item, s);
if (s[0] == 0) {
stdmessage("\pPlease name your shortcut before adding it.");
SetPort(dialog);
break;
}
if (gShortcuts[kShortcuts-1].jexiste) {
stdmessage("\pI'm sorry, no more shortcuts can be added. How many servers can there be, for heaven's sake?");
SetPort(dialog);
break;
}
cell.v = LAddRow(1, 32000, slist);
LSetCell((Ptr) &(s[1]), s[0], cell, slist);
verify(gShortcuts[cell.v].jexiste == false);
// add the shortcut to our memory
Shortcut *sc = &gShortcuts[cell.v];
sc->jexiste = true;
strncpy(sc->shortcut, (char *) &s[1], kPlayerNameLength-1);
if (s[0] < kPlayerNameLength) sc->shortcut[s[0]] = 0;
GetIText(ilist[pPort].item, s);
StringToNum(s, &gShortcuts[cell.v].port);
GetIText(ilist[pName].item, s);
strncpy(sc->name, (char *) &s[1], kPlayerNameLength - 1);
if (s[0] < kPlayerNameLength) sc->name[s[0]] = 0;
GetIText(ilist[pIP].item, s);
strncpy(sc->serverAddress, (char *) &s[1], kPlayerNameLength - 1);
if (s[0] < kPlayerNameLength) sc->serverAddress[s[0]] = 0;
// GetIText(ilist[pPassword].item, s);
// strncpy(sc->password, (char *) &s[1], kPlayerNameLength - 1);
// if (s[0] < kPlayerNameLength) sc->password[s[0]] = 0;
// copy in from fake text field
short tlen = kPlayerNameLength - 1;
if ((**fake).teLength < tlen)
tlen = (**fake).teLength;
for (short blah = 0; blah < tlen; blah++)
sc->password[blah] = ((char *) (*((**fake).hText)))[blah];
sc->password[tlen] = 0;
short val;
val = GetCtlValue((ControlHandle) ilist[pFics].item);
sc->serverType = !val;
val = GetCtlValue((ControlHandle) ilist[pTimeseal].item);
sc->timeseal = val;
sc->shortcut[kPlayerNameLength-1] = 0;
sc->name[kPlayerNameLength-1] = 0;
sc->serverAddress[kPlayerNameLength-1] = 0;
sc->password[kPlayerNameLength-1] = 0;
}
break;
case pRemoveButt: {
Cell cell = {0, 0};
if (LGetSelect(true, &cell, slist))
LDelRow(1, cell.v, slist);
// erase internal representation
short nnn;
for (nnn=cell.v; nnn<kShortcuts - 1; nnn++)
memcpy(&gShortcuts[nnn], &gShortcuts[nnn+1], sizeof(Shortcut));
gShortcuts[kShortcuts-1].jexiste = false;
}
break;
case pOpenButt: {
Cell cell = LLastClick(slist);
if (!LGetSelect(true, &cell, slist))
break;
// take the shortcut from our memory
Shortcut *sc = &gShortcuts[cell.v];
verify(sc->jexiste);
strcpy((char *) &s[1], sc->shortcut); s[0] = strlen(sc->shortcut);
SetIText(ilist[pShortcut].item, s);
NumToString(gShortcuts[cell.v].port, s);
SetIText(ilist[pPort].item, s);
strcpy((char *) &s[1], sc->name); s[0] = strlen(sc->name);
SetIText(ilist[pName].item, s);
strcpy((char *) &s[1], sc->serverAddress); s[0] = strlen(sc->serverAddress);
SetIText(ilist[pIP].item, s);
TESetText(sc->password, strlen(sc->password), fake);
for (i=0;sc->password[i];i++)
s[i+1] = '•';
s[0] = i;
SetIText(ilist[pPassword].item, s);
gPrefs.serverType = sc->serverType;
gPrefs.timeseal = sc->timeseal;
SetCtlValue((ControlHandle) ilist[pFics].item, sc->serverType == kFics);
SetCtlValue((ControlHandle) ilist[pIcc].item, sc->serverType == kIcc);
SetCtlValue((ControlHandle) ilist[pTimeseal].item, sc->timeseal);
}
break;
case pFics: case pIcc:
gPrefs.serverType = hitItem - pFics;
SetCtlValue((ControlHandle) ilist[pFics].item, gPrefs.serverType == kFics);
SetCtlValue((ControlHandle) ilist[pIcc].item, gPrefs.serverType == kIcc);
break;
case pTimeseal:
gPrefs.timeseal ^= 1;
SetCtlValue((ControlHandle) ilist[pTimeseal].item, gPrefs.timeseal);
break;
default: break;
}
if (hitItem == -1)
stdmessage("\pPlease fill in all fields (password optional).");
}
} while ((hitItem != pOkay) && (hitItem != pCancel));
okayed = hitItem == pOkay;
if (okayed) { // change real values
GetIText(ilist[pPort].item, s); StringToNum(s, port);
GetIText(ilist[pIP].item, s);
for (i=1;i<=s[0];i++)
address[i-1] = s[i];
address[i-1] = 0;
GetIText(ilist[pName].item, s);
for (i=1;i<=s[0];i++)
name[i-1] = s[i];
name[i-1] = 0;
// GetIText(ilist[pPassword].item, s);
// for (i=1;i<=s[0];i++)
// password[i-1] = s[i];
// password[i-1] = 0;
short tlen = kPlayerNameLength - 1;
if ((**fake).teLength < tlen)
tlen = (**fake).teLength;
for (short blah = 0; blah < tlen; blah++)
password[blah] = ((char *) (*((**fake).hText)))[blah];
password[tlen] = 0;
}
// HideWindow(addressWindow);
TEDispose(fake);
DisposDialog(dialog); // we Audi 5000, g
return okayed;
}
void
PrefDialog(void)
{
// items in dialog
enum {
pOkay = 1,
pCancel,
pAutoBug,
pWhite,
pBlack,
pAutoFlip,
pSmartClose,
pTrueColors,
pPieces,
pPieces2,
pPieces3,
pPieces4,
pChannelColors = 19,
pAdminColors,
pSmartText,
pSlowText,
pMinimal,
kFutzer,
kNumItems = kFutzer - 1,
kNumPieces = 2
};
Boolean okayed = false;
Str255 s;
iteminfo ilist[kNumItems+1];
short i, hitItem = -1;
WindowPtr saveport;
long reg, rep;
DialogPtr dialog;
OSErr err;
prefStruct oldprefs = gPrefs;
dialog = GetNewDialog(rPrefsDialog, nil, (WindowPtr) -1L);
verify(dialog);
// err = SetDialogDefaultItem(dialog, pOkay);
// err = SetDialogCancelItem(dialog, pCancel);
ShowWindow(dialog);
SetPort(dialog);
for (i=1;i<=kNumItems;i++) {
ilist[i].item = 0;
GetDItem(dialog, i, &ilist[i].itemType, &ilist[i].item, &ilist[i].box);
verify(ilist[i].item);
}
SetCtlValue((ControlHandle) ilist[pAutoFlip].item, gPrefs.autoFlip);
SetCtlValue((ControlHandle) ilist[pSmartClose].item, gPrefs.smartClose);
SetCtlValue((ControlHandle) ilist[pAutoBug].item, gPrefs.autoBug);
SetCtlValue((ControlHandle) ilist[pTrueColors].item, gPrefs.trueColors);
SetCtlValue((ControlHandle) ilist[pPieces + gPrefs.pieceSet].item, 1);
SetCtlValue((ControlHandle) ilist[pChannelColors].item, gPrefs.channelColors);
SetCtlValue((ControlHandle) ilist[pAdminColors].item, gPrefs.adminColors);
SetCtlValue((ControlHandle) ilist[pSmartText].item, gPrefs.smartText);
SetCtlValue((ControlHandle) ilist[pSlowText].item, gPrefs.slowText);
SetCtlValue((ControlHandle) ilist[pMinimal].item, gPrefs.minimal);
int ok;
EventRecord theEvent, eve;
DialogPtr dp;
char c;
Rect r1 = ilist[pWhite].box;
r1.left = r1.right + 16;
r1.right = r1.left + 48;
InsetRect(&r1, 0, -2);
Rect r2 = ilist[pBlack].box;
r2.left = r2.right + 16;
r2.right = r2.left + 48;
InsetRect(&r2, 0, -2);
do {
ok = GetNextEvent (everyEvent, &theEvent);
if (!ok)
continue;
if (theEvent.what == keyDown)
c = (theEvent.message & charCodeMask);
eve = theEvent;
if (theEvent.what == updateEvt) {
SetPort(dialog);
RGBForeColor(&gPrefs.colWhite);
PaintRect(&r1);
RGBForeColor(&gPrefs.colBlack);
PaintRect(&r2);
RGBForeColor(&rgbBlack);
}
hitItem = -1;
if (theEvent.what == keyDown && ((theEvent.modifiers & cmdKey) != 0)
&& c == '.')
hitItem = pCancel;
else if (theEvent.what == keyDown && c == '\r')
hitItem = pOkay;
else if (IsDialogEvent(&theEvent))
if (DialogSelect(&theEvent, &dp, &hitItem)) {
switch (hitItem) {
default: break;
}
}
switch (hitItem) {
case pBlack: {
Point pt = {0, 0};
if (GetColor(pt, "\pSet black square color", &gPrefs.colBlack, &gPrefs.colBlack)) {
SetPort(dialog);
RGBForeColor(&gPrefs.colBlack);
PaintRect(&r2);
RGBForeColor(&rgbBlack);
}
}
break;
case pWhite: {
Point pt = {0, 0};
if (GetColor(pt, "\pSet white square color", &gPrefs.colWhite, &gPrefs.colWhite)) {
SetPort(dialog);
RGBForeColor(&gPrefs.colWhite);
PaintRect(&r1);
RGBForeColor(&rgbBlack);
}
}
break;
case pSmartClose:
gPrefs.smartClose = !gPrefs.smartClose;
SetCtlValue((ControlHandle) ilist[pSmartClose].item, gPrefs.smartClose);
break;
case pAutoBug:
gPrefs.autoBug = !gPrefs.autoBug;
SetCtlValue((ControlHandle) ilist[pAutoBug].item, gPrefs.autoBug);
break;
case pAutoFlip:
gPrefs.autoFlip = !gPrefs.autoFlip;
SetCtlValue((ControlHandle) ilist[pAutoFlip].item, gPrefs.autoFlip);
break;
case pTrueColors:
gPrefs.trueColors = !gPrefs.trueColors;
SetCtlValue((ControlHandle) ilist[pTrueColors].item, gPrefs.trueColors);
break;
case pChannelColors:
gPrefs.channelColors = !gPrefs.channelColors;
SetCtlValue((ControlHandle) ilist[pChannelColors].item, gPrefs.channelColors);
break;
case pAdminColors:
gPrefs.adminColors = !gPrefs.adminColors;
SetCtlValue((ControlHandle) ilist[pAdminColors].item, gPrefs.adminColors);
break;
case pSmartText:
gPrefs.smartText = !gPrefs.smartText;
SetCtlValue((ControlHandle) ilist[pSmartText].item, gPrefs.smartText);
break;
case pSlowText:
gPrefs.slowText = !gPrefs.slowText;
SetCtlValue((ControlHandle) ilist[pSlowText].item, gPrefs.slowText);
break;
case pMinimal:
gPrefs.minimal = !gPrefs.minimal;
SetCtlValue((ControlHandle) ilist[pMinimal].item, gPrefs.minimal);
break;
case pPieces: case pPieces2: case pPieces3: case pPieces4:
short np = hitItem - pPieces;
if (np != gPrefs.pieceSet) {
SetCtlValue((ControlHandle) ilist[pPieces+gPrefs.pieceSet].item, 0);
SetCtlValue((ControlHandle) ilist[pPieces+np].item, 1);
gPrefs.pieceSet = np;
}
break;
default: break;
}
if (ok && theEvent.what == mouseDown)
QuickMouseDown(&eve);
} while ((hitItem != pOkay) && (hitItem != pCancel));
okayed = hitItem == pOkay;
if (!okayed) // change back values
memcpy(&gPrefs, &oldprefs, sizeof(prefStruct));
else {
// inval all game windows
Game *game = gGames;
while (game) {
SetPort((WindowPtr) game->wind);
InvalRect(&game->wind->portRect);
game = game->next;
}
}
DisposDialog(dialog); // we Audi 5000, g
}
void
PrefDialog2(void)
{
// items in dialog
enum {
pOkay = 1,
pCancel,
pBackgroundDrags,
pSoundTells,
kFutzer,
kNumItems = kFutzer - 1,
kNumPieces = 2
};
Boolean okayed = false;
Str255 s;
iteminfo ilist[kNumItems+1];
short i, hitItem = -1;
WindowPtr saveport;
long reg, rep;
DialogPtr dialog;
OSErr err;
prefStruct oldprefs = gPrefs;
dialog = GetNewDialog(rPrefs2Dialog, nil, (WindowPtr) -1L);
verify(dialog);
// err = SetDialogDefaultItem(dialog, pOkay);
// err = SetDialogCancelItem(dialog, pCancel);
ShowWindow(dialog);
SetPort(dialog);
for (i=1;i<=kNumItems;i++) {
ilist[i].item = 0;
GetDItem(dialog, i, &ilist[i].itemType, &ilist[i].item, &ilist[i].box);
verify(ilist[i].item);
}
SetCtlValue((ControlHandle) ilist[pBackgroundDrags].item, gPrefs.backgroundOnDrag);
SetCtlValue((ControlHandle) ilist[pSoundTells].item, gPrefs.soundTells);
int ok;
EventRecord theEvent, eve;
DialogPtr dp;
char c;
do {
ok = GetNextEvent (everyEvent, &theEvent);
if (!ok)
continue;
if (theEvent.what == keyDown)
c = (theEvent.message & charCodeMask);
eve = theEvent;
hitItem = -1;
if (theEvent.what == keyDown && ((theEvent.modifiers & cmdKey) != 0)
&& c == '.')
hitItem = pCancel;
else if (theEvent.what == keyDown && c == '\r')
hitItem = pOkay;
else if (IsDialogEvent(&theEvent))
if (DialogSelect(&theEvent, &dp, &hitItem)) {
switch (hitItem) {
default: break;
}
}
switch (hitItem) {
case pBackgroundDrags:
gPrefs.backgroundOnDrag = !gPrefs.backgroundOnDrag;
SetCtlValue((ControlHandle) ilist[pBackgroundDrags].item, gPrefs.backgroundOnDrag);
break;
case pSoundTells:
gPrefs.soundTells = !gPrefs.soundTells;
SetCtlValue((ControlHandle) ilist[pSoundTells].item, gPrefs.soundTells);
break;
default: break;
}
if (ok && theEvent.what == mouseDown)
QuickMouseDown(&eve);
} while ((hitItem != pOkay) && (hitItem != pCancel));
okayed = hitItem == pOkay;
if (!okayed) // change back values
memcpy(&gPrefs, &oldprefs, sizeof(prefStruct));
else {
// inval all game windows
Game *game = gGames;
while (game) {
SetPort((WindowPtr) game->wind);
InvalRect(&game->wind->portRect);
game = game->next;
}
}
DisposDialog(dialog); // we Audi 5000, g
}